Page({
  data: {
    valid: true,
    encryptedData: '',
    houseInfo: '',
    id: '',
    url: '',
    validTime: '',
    timeData: ''
  },
  onShareAppMessage() {
    return {
      title: '查看通行证',
      path: '/visitor_pkg/pages/passport/index?encryptedData=' + this.data.encryptedData,
      imageUrl: 'https://enjoy-plus.oss-cn-beijing.aliyuncs.com/images/share_poster.png',
    }
  },
  onChange(e) {
    const { days, hours, minutes, seconds } = e.detail
    console.log(days, hours, minutes, seconds)
    this.setData({
      timeData: e.detail,
      valid: (days + hours + minutes + seconds) > 0
    });
  },
  async onLoad({ id, encryptedData }) {
    // 小程序内的列表页跳转过来
    if (id) {
      const res = await wx.$http.get('/visitor/' + id)
      this.setData({
        ...res
      })
    }
    // 别人分享过来的
    if (encryptedData) {
      console.log('别人分享过来的', encryptedData)
      const res = await wx.$http.get('/visitor/share/' + encryptedData)
      this.setData({
        ...res
      })
    }
  },
  saveImage() {
    // getImageInfo 获取网络图片信息 ===> 本地临时地址
    wx.getImageInfo({
      src: this.data.url,
      success: (res) => {
        console.log('图片信息地址：', res.path)
        // 保存图片到相册： 必须是本地的地址
        wx.saveImageToPhotosAlbum({
          filePath: res.path,
          success: (re) => {
            console.log(re)
          }
        })
      }
    })
  }
})
